﻿using Raven.Client.Document;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static DocumentStore docStore = null;

        static void Main(string[] args)
        {
            docStore = new DocumentStore { ConnectionStringName = "RavenDBConnection" };
            docStore.Initialize();
            docStore.Conventions.MaxNumberOfRequestsPerSession = 1000;
        }

        void InsertData()
        {
            using (var session=docStore.OpenSession())
            {
                session.Store(new Student { Id = 1, Name = "Lisa" });
                session.Store(new Student { Id = 2, Name = "Paul" });
                session.Store(new Student { Id = 3, Name = "Raul" });
                session.Store(new Student { Id = 4, Name = "Zosia" });

                session.SaveChanges();
            }
        }

        List<Student> SelectData()
        {
            using (var session=docStore.OpenSession())
            {
                return session.Query<Student>().ToList();
            }
        }

        void UpdateData(int id)
        {
            using (var session=docStore.OpenSession())
            {
                var item = session.Load<Student>(id);
                item.Name = "Name Changed";
                session.SaveChanges();
            }
        }

        void DeleteData(Student item)
        {
            using (var session=docStore.OpenSession())
            {
                session.Delete<Student>(item);
                session.SaveChanges();
            }
        }

        public class Student
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }
    }
}
